﻿namespace Infra.NHibernateUnitOfWork.Configuration
{
    using System.IO;
    using System.Xml;
    using NHibernate.Cfg;
    using SourceCodeRepository.Common;

    public class ProductionConfigurationContext : IConfigurationContext
    {
        public Configuration Configuration
        {
            get 
            {
                
                var configuration = new Configuration();

                string hibernateConfig = "hibernate.cfg.xml";
                
                string filePath = Path.Combine(Path.Combine(CommonConstants.ConfigurationDirectory,CommonConstants.ProductionDirectory), hibernateConfig);

                hibernateConfig = Path.Combine(CommonConstants.ApplicationPath, filePath);

                if (File.Exists(hibernateConfig))
                    configuration.Configure(new XmlTextReader(hibernateConfig));

                return configuration;
            }
        }
    }
}